package org.firestorm.traficforecast.database;

import java.util.ArrayList;
import org.firestorm.traficforecast.astar.Way;

public class Road {

    private String id;
    private String name;
    private ArrayList<MyNode> nodeList;
    private int status;
    private double len;
    private MyNode start;
    private MyNode finish;
    private ArrayList<String> nextRoad;

    public static void main(String[] args) {
//		DateFormat df = new SimpleDateFormat("dd/mm/yyyy HH:mm:ss");
//		Date date = new Date();
//		System.out.println(df.format(date));
//		Road road= RoadDAO.getRoad("102307663");
//		for(int i = 0; i < road.getNextRoad().size(); i++){
//			System.out.println(road.getNextRoad().get(i).getNextRoad().size());
//		}
//		date = new Date();
//		System.out.println(df.format(date));
        ArrayList<Road> listRoad = RoadDAO.getRoadStatus("84786846");
        System.out.println(listRoad.size());
        for (int i = 0; i < listRoad.size(); i++) {
        }

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public ArrayList<MyNode> getNodeList() {
        return nodeList;
    }

    public void setNodeList(ArrayList<MyNode> nodeList) {
        this.nodeList = nodeList;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public double getLen() {
        return len;
    }
    public double getLenEstimate(){
    	double d = len;
        if(status == 0 ){
            d = d*2;
        }else if(status == 1){
            d = d*5;
        }
        return d;
    }
    public void setLen(double len) {
        this.len = len;
    }

    public ArrayList<Road> getNextRoad() {
        ArrayList<Road> next = new ArrayList<Road>();
        for (int i = 0; i < this.nextRoad.size(); i++) {
            next.add(RoadDAO.getRoad(this.nextRoad.get(i)));
        }
        return next;
    }

    public ArrayList<Road> getNextRoad(ArrayList<Way> fringe, ArrayList<String> ids) {
        ArrayList<Road> next = new ArrayList();
        for (int i = 0; i < this.nextRoad.size(); i++) {
            if (!test(fringe, ids, nextRoad.get(i))) {
                next.add(RoadDAO.getRoad(this.nextRoad.get(i)));
            }
        }
        return next;
    }

    public boolean test(ArrayList<Way> fringe, ArrayList<String> ids, String r) {
        boolean b = false;
        for (int i = 0; i < ids.size(); i++) {
            if (ids.get(i).equals(r)) {
                b = true;
                break;
            }
        }
        if (!b) {
            for (int i = 0; i < fringe.size(); i++) {
                if (fringe.get(i).getRoad().getId().equals(r)) {
                    b = true;
                    break;
                }
            }
        }
        return b;
    }

    public void setNextRoad(ArrayList<String> nextRoad) {
        this.nextRoad = nextRoad;
    }

    public MyNode getStart() {
        return start;
    }

    public void setStart(MyNode start) {
        this.start = start;
    }

    public MyNode getFinish() {
        return finish;
    }

    public void setFinish(MyNode finish) {
        this.finish = finish;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}
